package com.xiong.wuliao.util;

import com.xiong.wuliao.entity.Special;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 专题详情页面的数据解析
 * Created by Administrator on 2016/11/7.
 */
public class SpecialJSON {
    public static List<Special> saveSpecialData(String s) {
        List<Special> specialList = new ArrayList<>();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(s.trim());
            JSONObject object = jsonObject.optJSONObject("data");
            Special special = new Special();

            special.setComments_count(object.optString("comments_count"));
            special.setContent_url(object.optString("content_url"));
            special.setCover_image_url(object.optString("cover_image_url"));
            special.setCreated_at(object.optString("created_at"));
            special.setId(object.optString("id"));
            special.setLiked(object.optBoolean("liked"));
            special.setLikes_count(object.optString("likes_count"));
            special.setShares_count(object.optString("shares_count"));
            special.setTitle(object.optString("title"));

            specialList.add(special);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return specialList;
    }
}
